<?php
/**
 * 功能描述：	系统后台主框架
 * @datetime	2022-07-07
 * @version   	v2.3.0
 * @author   	ZHL
 * @copyrigh  	2022 ZHL 版权所有
 */

class Admin_IndexController extends Controller {

    // 是否登录
    function __construct($controller, $action) {
        parent::__construct($controller, $action);
        $loginSer = new Admin_LoginServe();
        $loginSer->judgeSessionLogin($controller, $action, 1);
    }

    /**
     * Notes:后台框架页面
     * User: ZhuHaili
     */
    public function index() {
        // 标题
		$this->set('title', '后台系统-'.$GLOBALS['ADMIN']['sys_name']);
        // 后台名称展示(左上)
        $title = '后台管理系统';
        if(isset($GLOBALS['ADMIN']['sys_name']) && $GLOBALS['ADMIN']['sys_name']){
            $title = mbSubstr($GLOBALS['ADMIN']['sys_name'], 0, 20);
        }$this->set('webname', $title);
        // 获取用户session信息
        $loginUserInfo = SYS_SESSIONS_GET(LOGIN_SESSION_FIX.'alogin_info');
        // 用户昵称
        $userName = '';
        if(isset($loginUserInfo['nickname']) && $loginUserInfo['nickname']){
            $userName = mbSubstr($loginUserInfo['nickname'], 0, 10);
        }$this->set('adminName', $userName);
        // 用户头像
		$headimg = ADMIN_HEAD_PIC;
		if(isset($loginUserInfo['headimg']) && $loginUserInfo['headimg']) {
            $headimg = $loginUserInfo['headimg'];
        }$this->set('headimg', $headimg);
        // 用户等级
        $userLevel = '';
        if(isset($loginUserInfo['levels']) && $loginUserInfo['levels']){
            $userLevel = $loginUserInfo['levels'];
        }$this->set('userLevel', $userLevel);
        // 用户id
        $userId = '';
        if(isset($loginUserInfo['id']) && $loginUserInfo['id']){
            $userId = $loginUserInfo['id'];
        }$this->set('userId', $userId);

        // 后台左侧菜单
        $classSer = new Admin_MenuServe();
        $navLeft = $classSer->getClassList(2, 1);
        $this->set('navLeft', $navLeft);
        // 后台顶部菜单
        $navTop = $classSer->getClassList(1, 1);
        $this->set('navTop', $navTop);
        // 映射模板
		$this->display();
    }

    /**
     * Notes: 后台主页
     * User: ZhuHaili
     */
    public function main(){
        $sys_main_flag = isset($GLOBALS['ADMIN']['sys_main_flag']) ? $GLOBALS['ADMIN']['sys_main_flag'] : '1';
        if($sys_main_flag == 2){
            SYS_REDIRECT('admin_index_main2');
        }else{
            SYS_REDIRECT('admin_index_main1');
        }
    }

    /**
     * Notes:后台主页
     * User: ZhuHaili
     */
    public function main1() {
        // title标签标题
		$this->set('title', $GLOBALS['ADMIN']['sys_name']);
        $pvs = $uvs = $ips = 0;
		// 获取当日访客统计信息（总pv,总uv,总IP）
        $ser = new C_ClientServe();
        $countRes = $ser->getDayStat(date('Y-m-d'), date('Y-m-d'));
        if($countRes['code'] == 10000){
            $pvs = $countRes['data']['pvs'];
            $uvs = $countRes['data']['uvs'];
            $ips = $countRes['data']['ips'];
        }
        $this->set('pvs', $pvs);
        $this->set('uvs', $uvs);
        $this->set('ips', $ips);
        $this->display();
    }

    /**
     * Notes:后台主页2
     * User: ZhuHaili
     */
    public function main2(){
        // title标签标题
        $this->set('title', $GLOBALS['ADMIN']['sys_name']);

        $loginUserInfo = SYS_SESSIONS_GET(LOGIN_SESSION_FIX.'alogin_info');
        $loginTime = date('Y-m-d');
        $logincount = '1';
        if(isset($loginUserInfo['logincount']) && $loginUserInfo['logincount']){
            $loginTime = $loginUserInfo['logintime'];
            $logincount = $loginUserInfo['logincount'];
        }

        $userLoginInfo['now_ip'] = clientIP();
        $userLoginInfo['total_count'] = $logincount;
        $userLoginInfo['last_time'] = $loginTime;

        $this->set('userLoginInfo', $userLoginInfo);
        $this->display();
    }

    /**
     * Notes:获取用户登录日志
     * User: ZhuHaili
     */
    public function loginlog(){
        $startDate = Fun::input('startDate', date('Y-m-d'));
        $endDate = Fun::input('endDate', date('Y-m-d'));
        $indexSer = new Admin_IndexServe();
        $result = $indexSer->getUserLoginLogList($startDate, $endDate);
        Fun::json($result,true);
    }

    /**
     * Notes:获取用户操作日志
     * User: ZhuHaili
     */
    public function operatelog(){
        $startDate = Fun::input('startDate', date('Y-m-d'));
        $endDate = Fun::input('endDate', date('Y-m-d'));
        $indexSer = new Admin_IndexServe();
        $result = $indexSer->getUserOperateLogList($startDate, $endDate);
        Fun::json($result,true);
    }
}